home *** CD-ROM | disk | FTP | other *** search
/ Plug-In Power Pack for Netscape Communicator / Plug-In Power Pack for Netscape Communicator.iso / plugins / dataviews / dvtools / demos / dwpdemo / dwp_dyn.c < prev    next >
C/C++ Source or Header  |  1997-05-08  |  15KB  |  547 lines

  1. #ifndef lint
  2. static char SccsId[]= "@(#)dwp_dyn.c    V1.7    3/15/95";
  3. #endif
  4.  
  5.  
  6. /*------------------------------------------------------------------
  7. | file name -- dwp_dyn.c
  8. |
  9. | functions             Description
  10. | ---------             -----------
  11. | HandleDynamics        Display the latest data.
  12. | setup_main_window     Set up the display deques for the main window.
  13. | setup_ammonia_window  Set up the display deques for the ammonia
  14. |                       subsystem  window.
  15. | setup_hp_drum_window  Set up the display deques for the high
  16. |                       pressure drum window.
  17. | setup_lp_drum_window  Set up the display deques for the low
  18. |                       pressure drum window.
  19. | setup_hand_window     Set up the display deques for the hand/
  20. |                       autostation window.
  21. | maindqadd             Add the dynamic objects to the main window deque.
  22. | v3dqadd               Add the dynamic objects to the valve 3 deque.
  23. | v4dqadd               Add the dynamic objects to the valve 4 deque.
  24. | ammoniadqadd          Add the dynamic objects to the ammonia subsystem
  25. |                       window deque.
  26. | v1dqadd               Add the dynamic objects to the valve 1 deque.
  27. | v2dqadd               Add the dynamic objects to the valve 2 deque.
  28. | hpdrumdqadd           Add the dynamic objects to the high pressure
  29. |                       drum window deque.
  30. | lpdrumdqadd           Add the dynamic objects to the low pressure
  31. |                       drum window deque.
  32. | handdqadd             Add the dynamic objects to the hand/autostation
  33. |                       deque.
  34. | change_valve          Turn the valve status on or off.
  35. | reset                 Reset the hand/autostation values to previously
  36. |                       defined values.
  37. |-----------------------------------------------------------------*/
  38.  
  39. #include "std.h"
  40. #include "dvstd.h"
  41. #include "dvtools.h"
  42. #include "VOstd.h"
  43. #include "Tfundecl.h"
  44. #include "dvGR.h"
  45. #include "dwp_vars.h"
  46. #include "dwp_data.h"
  47. #include "VGfundecl.h"
  48. #include "VOfundecl.h"
  49. #include "dwp_fundecl.h"
  50.  
  51.  
  52.  
  53. /***************** Begin Function Declarations *************/
  54. LOCAL  ADDRESS maindqadd V_P_((OBJECT obj, char *name, ADDRESS argblock));
  55. LOCAL  ADDRESS v3dqadd V_P_((OBJECT obj, char *name, ADDRESS argblock));
  56. LOCAL  ADDRESS v4dqadd V_P_((OBJECT obj, char *name, ADDRESS argblock));
  57. LOCAL  ADDRESS ammoniadqadd V_P_((OBJECT obj, char *name, ADDRESS argblock));
  58. LOCAL  ADDRESS v1dqadd V_P_((OBJECT obj, char *name, ADDRESS argblock));
  59. LOCAL  ADDRESS v2dqadd V_P_((OBJECT obj, char *name, ADDRESS argblock));
  60. LOCAL  ADDRESS hpdrumdqadd V_P_((OBJECT obj, char *name, ADDRESS argblock));
  61. LOCAL  ADDRESS lpdrumdqadd V_P_((OBJECT obj, char *name, ADDRESS argblock));
  62. LOCAL  ADDRESS handdqadd V_P_((OBJECT obj, char *name, ADDRESS argblock));
  63. /***************** End Function Declarations *************/
  64.  
  65. /*-----------------------------------------------------------------
  66. |
  67. |  HandleDynamics
  68. |       Performs the functions needed to update the display to
  69. |       reflect the latest data.
  70. */
  71. void HandleDynamics 
  72. V_P_ ((void))
  73. {
  74.   INT i;
  75.  
  76.   /* If we are in the middle of opening a window, don't do anything.
  77.   |
  78.   |  This HandleDynamics() routine is called from a TimeOutProc...
  79.   |  which could get triggered when we call TscOpenSet with
  80.   |  V_EXPOSURE_BLOCK set to YES. TscOpen will dispatch all events
  81.   |  while its waiting for the EXPOSE_EVENT and this timeout would get
  82.   |  called. To avoid "re-entering" the DataViews code, just return
  83.   |  under this condition.
  84.   */
  85.   if (WaitingForExpose == YES)
  86.     return;
  87.  
  88.   /* set the high high and low low values */
  89.   hihi = highvalue + 10;
  90.   lolo = lowvalue - 10;
  91.  
  92.   /* set the alarm status */
  93.   if (setpoint < lowvalue)
  94.     alarm_status = ALARM_LOW;
  95.   else if (setpoint > highvalue)
  96.     alarm_status = ALARM_HIGH;
  97.   else
  98.     alarm_status = ALARM_NORMAL;
  99.  
  100.   /* update the dynamic objects */
  101.   for (i = 0; i < MAXWINS; i++)
  102.     {
  103.       if (window_status[i] == OPEN)
  104.         {
  105.           if (dynamic_status[i] == ON)
  106.             {
  107.               INT size, j;
  108.  
  109.               TscSetCurrentScreen (DVscreen[i]);
  110.               TdlReadData (dsl[i]);
  111. /*
  112.           TdpDrawNext( drawport[i] );
  113. */
  114.               size = VOdqSize (displaydq[i]);
  115.               for (j = 1; j <= size; j++)
  116.                 {
  117.                   TdpDrawNextObject (drawport[i], VOdqGetEntry (displaydq[i], j));
  118.                 }
  119.             }
  120.         }
  121.     }
  122.  
  123. }
  124.  
  125.  
  126. /*--------------------------------------------------------------------
  127. |
  128. |  setup_main_window
  129. |       Set up the display deques for the main window.
  130. */
  131. void setup_main_window 
  132. V_P_ ((void))
  133. {
  134.   maindq = VOdqCreate ((int)NULL);
  135.   v3dq = VOdqCreate ((int)NULL);
  136.   v4dq = VOdqCreate ((int)NULL);
  137.   displaydq[MAIN] = VOdqCreate ((int)NULL);
  138.  
  139.   /* put all the dynamic objects into the correct deque */
  140.   TdrForEachNamedObject (drawing[MAIN], maindqadd, NULL);
  141.   VOdqAddDq (displaydq[MAIN], TOP, maindq);
  142.  
  143.   /* put the valve 3 dynamic objects into the valve 3 deque */
  144.   if (v3status == ON)
  145.     {
  146.       TdrForEachNamedObject (drawing[MAIN], v3dqadd, NULL);
  147.       VOdqAddDq (displaydq[MAIN], TOP, v3dq);
  148.     }
  149.  
  150.   /* put the valve 4 dynamic objects into the valve 4 deque */
  151.   if (v4status == ON)
  152.     {
  153.       TdrForEachNamedObject (drawing[MAIN], v4dqadd, NULL);
  154.       VOdqAddDq (displaydq[MAIN], TOP, v4dq);
  155.     }
  156.  
  157.   v3rotate = current_setpoint[3];
  158.   v4rotate = current_setpoint[4];
  159.  
  160. }
  161.  
  162. /*---------------------------------------------------------------
  163. |
  164. |  maindqadd
  165. |       Add the main window dynamic objects which do not go
  166. |       in the valve 3 or valve 4 deque.
  167. */
  168. /* ARGSUSED */
  169. LOCAL ADDRESS 
  170. maindqadd (obj, name, argblock)
  171.      OBJECT obj;
  172.      char *name;
  173.      ADDRESS argblock;
  174. {
  175.   if (strcmp (name, "dyn") == 0)
  176.     VOdqAdd (maindq, TOP, obj);
  177.   else if (strcmp (name, "W:Valve3") == 0)
  178.     VOdqAdd (maindq, TOP, obj);
  179.   else if (strcmp (name, "W:Valve4") == 0)
  180.     VOdqAdd (maindq, TOP, obj);
  181.  
  182.   return (V_CONTINUE_TRAVERSAL);
  183. }
  184.  
  185. /*---------------------------------------------------------------
  186. |
  187. |  v3dqadd
  188. |       Add the main window dynamic objects which are controlled
  189. |       by valve 3.
  190. */
  191. /* ARGSUSED */
  192. LOCAL ADDRESS 
  193. v3dqadd (obj, name, argblock)
  194.      OBJECT obj;
  195.      char *name;
  196.      ADDRESS argblock;
  197. {
  198.   if (strcmp (name, "v3flow") == 0)
  199.     VOdqAdd (v3dq, TOP, obj);
  200.   else if (strcmp (name, "W:hp_drum_detail") == 0)
  201.     VOdqAdd (v3dq, TOP, obj);
  202.  
  203.   return (V_CONTINUE_TRAVERSAL);
  204. }
  205.  
  206. /*---------------------------------------------------------------
  207. |
  208. |  v4dqadd
  209. |       Add the main window dynamic objects which are controlled
  210. |       by valve 4.
  211. */
  212. /* ARGSUSED */
  213. LOCAL ADDRESS 
  214. v4dqadd (obj, name, argblock)
  215.      OBJECT obj;
  216.      char *name;
  217.      ADDRESS argblock;
  218. {
  219.   if (strcmp (name, "v4flow") == 0)
  220.     VOdqAdd (v4dq, TOP, obj);
  221.   else if (strcmp (name, "W:lp_drum_detail") == 0)
  222.     VOdqAdd (v4dq, TOP, obj);
  223.  
  224.   return (V_CONTINUE_TRAVERSAL);
  225. }
  226.  
  227.  
  228. /*--------------------------------------------------------------------
  229. |
  230. |  setup_ammonia_window
  231. |       Set up the display deques for the ammonia subsystem window.
  232. */
  233. void setup_ammonia_window 
  234. V_P_ ((void))
  235. {
  236.  
  237.   v1dq = VOdqCreate ((int)NULL);
  238.   v2dq = VOdqCreate ((int)NULL);
  239.   displaydq[AMMONIA] = VOdqCreate ((int)NULL);
  240.   TdrForEachNamedObject (drawing[AMMONIA], ammoniadqadd, NULL);
  241.  
  242.  
  243.   /* put the valve 1 dynamic objects into the valve 1 deque */
  244.   if (v1status == ON)
  245.     {
  246.       TdrForEachNamedObject (drawing[AMMONIA], v1dqadd, NULL);
  247.       VOdqAddDq (displaydq[AMMONIA], TOP, v1dq);
  248.     }
  249.  
  250.   /* put the valve 2 dynamic objects into the valve 2 deque */
  251.   if (v2status == ON)
  252.     {
  253.       TdrForEachNamedObject (drawing[AMMONIA], v2dqadd, NULL);
  254.       VOdqAddDq (displaydq[AMMONIA], TOP, v2dq);
  255.     }
  256.  
  257.   v1rotate = current_setpoint[1];
  258.   v2rotate = current_setpoint[2];
  259. }
  260.  
  261. /*---------------------------------------------------------------
  262. |
  263. |  ammoniadqadd
  264. |       Add the ammonia subsystem window dynamic objects which do not go
  265. |       in the valve 1 or valve 2 deque.
  266. */
  267. /* ARGSUSED */
  268. LOCAL ADDRESS 
  269. ammoniadqadd (obj, name, argblock)
  270.      OBJECT obj;
  271.      char *name;
  272.      ADDRESS argblock;
  273. {
  274.  
  275.   if (strcmp (name, "W:Valve1") == 0)
  276.     VOdqAdd (displaydq[AMMONIA], TOP, obj);
  277.   else if (strcmp (name, "W:Valve2") == 0)
  278.     VOdqAdd (displaydq[AMMONIA], TOP, obj);
  279.  
  280.   return (V_CONTINUE_TRAVERSAL);
  281. }
  282.  
  283. /*---------------------------------------------------------------
  284. |
  285. |  v1dqadd
  286. |       Add the ammonia subsystem window dynamic objects which
  287. |    are controlled by valve 1.
  288. */
  289. /* ARGSUSED */
  290. LOCAL ADDRESS 
  291. v1dqadd (obj, name, argblock)
  292.      OBJECT obj;
  293.      char *name;
  294.      ADDRESS argblock;
  295. {
  296.  
  297.   if (strcmp (name, "v1flow") == 0)
  298.     VOdqAdd (v1dq, TOP, obj);
  299.  
  300.   return (V_CONTINUE_TRAVERSAL);
  301. }
  302.  
  303. /*---------------------------------------------------------------
  304. |
  305. |  v2dqadd
  306. |       Add the ammonia subsystem window dynamic objects which
  307. |    are controlled by valve 2.
  308. */
  309. /* ARGSUSED */
  310. LOCAL ADDRESS 
  311. v2dqadd (obj, name, argblock)
  312.      OBJECT obj;
  313.      char *name;
  314.      ADDRESS argblock;
  315. {
  316.  
  317.   if (strcmp (name, "v2flow") == 0)
  318.     VOdqAdd (v2dq, TOP, obj);
  319.  
  320.   return (V_CONTINUE_TRAVERSAL);
  321. }
  322.  
  323.  
  324. /*--------------------------------------------------------------------
  325. |
  326. |  setup_hp_drum_window
  327. |       Set up the display deques for the high pressure drum window.
  328. */
  329. void setup_hp_drum_window 
  330. V_P_ ((void))
  331. {
  332.   displaydq[HP_DRUM] = VOdqCreate ((int)NULL);
  333.   TdrForEachNamedObject (drawing[HP_DRUM], hpdrumdqadd, NULL);
  334. }
  335.  
  336. /*---------------------------------------------------------------
  337. |
  338. |  hpdrumdqadd
  339. |       Add the high pressure drum  window dynamic objects to the
  340. |       dynamic deque.
  341. */
  342. /* ARGSUSED */
  343. LOCAL ADDRESS 
  344. hpdrumdqadd (obj, name, argblock)
  345.      OBJECT obj;
  346.      char *name;
  347.      ADDRESS argblock;
  348. {
  349.  
  350.   if (strcmp (name, "dyn") == 0)
  351.     {
  352.       VOdqAdd (displaydq[HP_DRUM], TOP, obj);
  353.     }
  354.  
  355.   return (V_CONTINUE_TRAVERSAL);
  356. }
  357.  
  358.  
  359. /*--------------------------------------------------------------------
  360. |
  361. |  setup_lp_drum_window
  362. |       Set up the display deques for the low pressure drum window.
  363. */
  364. void setup_lp_drum_window 
  365. V_P_ ((void))
  366. {
  367.   displaydq[LP_DRUM] = VOdqCreate ((int)NULL);
  368.   TdrForEachNamedObject (drawing[LP_DRUM], lpdrumdqadd, NULL);
  369. }
  370.  
  371. /*---------------------------------------------------------------
  372. |
  373. |  lpdrumdqadd
  374. |       Add the low pressure drum window dynamic objects to the
  375. |       dynamic deque.
  376. */
  377. /* ARGSUSED */
  378. LOCAL ADDRESS 
  379. lpdrumdqadd (obj, name, argblock)
  380.      OBJECT obj;
  381.      char *name;
  382.      ADDRESS argblock;
  383. {
  384.  
  385.   if (strcmp (name, "dyn") == 0)
  386.     {
  387.       VOdqAdd (displaydq[LP_DRUM], TOP, obj);
  388.     }
  389.  
  390.   return (V_CONTINUE_TRAVERSAL);
  391. }
  392.  
  393.  
  394.  
  395. /*--------------------------------------------------------------------
  396. |
  397. |  setup_hand_window
  398. |       Set up the display deques for the hand/autostation window.
  399. */
  400. void setup_hand_window 
  401. V_P_ ((void))
  402. {
  403.  
  404.   displaydq[HAND] = VOdqCreate ((int)NULL);
  405.   TdrForEachNamedObject (drawing[HAND], handdqadd, NULL);
  406.   setpoint = current_setpoint[whichvalve];
  407.   highvalue = current_highvalue[whichvalve];
  408.   hihi = highvalue + 10;
  409.   lowvalue = current_lowvalue[whichvalve];
  410.   lolo = lowvalue - 10;
  411.   valvenumber = (FLOAT) whichvalve;
  412.  
  413. }
  414.  
  415.  
  416. /*---------------------------------------------------------------
  417. |
  418. |  handdqadd
  419. |       Add the hand/autostation window dynamic objects to the
  420. |       dynamic deque.
  421. */
  422. /* ARGSUSED */
  423. LOCAL ADDRESS 
  424. handdqadd (obj, name, argblock)
  425.      OBJECT obj;
  426.      char *name;
  427.      ADDRESS argblock;
  428. {
  429.  
  430.   if (strcmp (name, "dyn") == 0)
  431.     {
  432.       VOdqAdd (displaydq[HAND], TOP, obj);
  433.     }
  434.  
  435.   return (V_CONTINUE_TRAVERSAL);
  436. }
  437.  
  438. /*---------------------------------------------------------------
  439. |
  440. |  change_valve
  441. |       For the selected valve check the values which indicate
  442. |       if the valve needs to be turned on or off and take the
  443. |       appropriate action.
  444. */
  445. void change_valve 
  446. V_P_ ((void))
  447. {
  448.   current_setpoint[whichvalve] = setpoint;
  449.   current_highvalue[whichvalve] = highvalue;
  450.   current_lowvalue[whichvalve] = lowvalue;
  451.   hihi = highvalue + 10;
  452.   lolo = lowvalue - 10;
  453.   switch (whichvalve)
  454.     {
  455.     case 1:
  456.       {
  457.         /* turn the flow on */
  458.         if ((v1status == OFF) && (setpoint >= MINFLOW))
  459.           {
  460.             TdrForEachNamedObject (drawing[AMMONIA], v1dqadd, NULL);
  461.             VOdqAddDq (displaydq[AMMONIA], TOP, v1dq);
  462.             v1status = ON;
  463.           }
  464.         /* turn the flow off */
  465.         else if ((v1status == ON) && (setpoint < MINFLOW))
  466.           {
  467.             VOdqDeleteDq (displaydq[AMMONIA], v1dq);
  468.             v1status = OFF;
  469.           }
  470.         v1rotate = setpoint;
  471.         break;
  472.       }
  473.     case 2:
  474.       {
  475.         /* turn the flow on */
  476.         if ((v2status == OFF) && (setpoint >= MINFLOW))
  477.           {
  478.             TdrForEachNamedObject (drawing[AMMONIA], v2dqadd, NULL);
  479.             VOdqAddDq (displaydq[AMMONIA], TOP, v2dq);
  480.             v2status = ON;
  481.           }
  482.         /* turn the flow off */
  483.         else if ((v2status == ON) && (setpoint < MINFLOW))
  484.           {
  485.             VOdqDeleteDq (displaydq[AMMONIA], v2dq);
  486.             v2status = OFF;
  487.           }
  488.         v2rotate = setpoint;
  489.         break;
  490.       }
  491.     case 3:
  492.       {
  493.         /* turn the flow on */
  494.         if ((v3status == OFF) && (setpoint >= MINFLOW))
  495.           {
  496.             TdrForEachNamedObject (drawing[MAIN], v3dqadd, NULL);
  497.             VOdqAddDq (displaydq[MAIN], TOP, v3dq);
  498.             v3status = ON;
  499.           }
  500.         /* turn the flow off */
  501.         else if ((v3status == ON) && (setpoint < MINFLOW))
  502.           {
  503.             VOdqDeleteDq (displaydq[MAIN], v3dq);
  504.             v3status = OFF;
  505.           }
  506.         v3rotate = setpoint;
  507.         break;
  508.       }
  509.     case 4:
  510.       {
  511.         /* turn the flow on */
  512.         if ((v4status == OFF) && (setpoint >= MINFLOW))
  513.           {
  514.             TdrForEachNamedObject (drawing[MAIN], v4dqadd, NULL);
  515.             VOdqAddDq (displaydq[MAIN], TOP, v4dq);
  516.             v4status = ON;
  517.           }
  518.         /* turn the flow off */
  519.         else if ((v4status == ON) && (setpoint < MINFLOW))
  520.           {
  521.             VOdqDeleteDq (displaydq[MAIN], v4dq);
  522.             v4status = OFF;
  523.           }
  524.         v4rotate = setpoint;
  525.         break;
  526.       }
  527.     }
  528. }
  529.  
  530. /*-----------------------------------------------------------------
  531. |
  532. |  reset
  533. |       Reset the hand/autostation values to their previously
  534. |       confirmed values.
  535. */
  536. void reset 
  537. V_P_ ((void))
  538. {
  539.  
  540.   setpoint = current_setpoint[whichvalve];
  541.   highvalue = current_highvalue[whichvalve];
  542.   lowvalue = current_lowvalue[whichvalve];
  543.   hihi = highvalue + 10;
  544.   lolo = lowvalue - 10;
  545.  
  546. }
  547.